<?php

namespace app\controllers;

use app\components\CommonTool;
use app\models\User;
use Yii;
use yii\web\Controller;

class SiteController extends Controller
{
    public function actionIndex()
    {
        $count = User::find()->count();
        $isOauthed = User::findOne(Yii::$app->user->id) != null;
        return $this->render('index', [
            'count' => 1000 + $count,
            'isOauthed' => $isOauthed,
            'list' => Yii::$app->user->isGuest ? User::find()->limit(30)->orderBy(['created_at' => SORT_DESC])->asArray()->all() : User::find()->where(['<>', 'openid', Yii::$app->user->id])->limit(30)->orderBy(['created_at' => SORT_DESC])->asArray()->all()
        ]);
    }

    public function actionError()
    {
        $error = Yii::$app->errorHandler->exception;
        if (!empty($error)) {
            $this->layout = CommonTool::isWechat() ? 'mobile' : 'main';
            return $this->render('/oauth/error', $error);
        }
    }
}
